#!/bin/bash

project_name="noip-updator"
release_version="v$(date +%Y.%m.%d.%H%M%S)"
echo $release_version

release_dir=./release
rm -rf $release_dir/*
mkdir -p $release_dir

cd  $(dirname $0)

gofmt -w ./

for goos in "linux" "darwin" "freebsd" "windows"
do
    if [ "$goos" == "windows" ]; then
      obj_name=$project_name.exe
    else
      obj_name=$project_name
    fi
    
    echo "build $goos amd64"
    GOOS=$goos GOARCH=amd64 go build -o $obj_name *.go
    zip $release_dir/$project_name-$goos-amd64-$release_version.zip $obj_name config/application.yml.sample log

    echo "build $goos 386"
    GOOS=$goos GOARCH=386 go build -o $obj_name *.go
    zip $release_dir/$project_name-$goos-386-$release_version.zip $obj_name config/application.yml.sample log

    echo "build $goos arm64"
    GOOS=$goos GOARCH=arm64 go build -o $obj_name *.go
    zip $release_dir/$project_name-$goos-arm64-$release_version.zip $obj_name config/application.yml.sample log

    rm -f $obj_name
done

cd $release_dir
for file in ./*
do
    md5sum $file >> sha1sum.txt
done